package cn.aws360.boot.auth.api.service.impl;

import cn.aws360.boot.auth.api.LoginApi;
import cn.aws360.boot.auth.api.helper.LoginHelper;
import cn.aws360.boot.auth.api.pojo.response.LoginUserModel;
import cn.aws360.boot.base.api.constant.BaseConstant;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;

/**
 * @author junnan
 */
@Slf4j
@Service
@RequiredArgsConstructor
@ConditionalOnProperty(name = BaseConstant.APP + ".auth.enable", havingValue = "false")
public class MockLoginServiceImpl implements LoginApi {

    private final LoginUserModel loginUserModel = LoginUserModel.builder()
            .id(1)
            .deptId(1)
            .username("admin")
            .password(LoginHelper.encryptPassword("123456"))
            .mobile("18610860000")
            .build();

    @Override
    public void checkCaptcha(String uuid, String captcha) {

    }

    @Override
    public LoginUserModel loadUserByName(String username) {
        return loginUserModel;
    }

    @Override
    public LoginUserModel loadUserByMobile(String mobile) {
        return loginUserModel;
    }

    @Override
    public LoginUserModel loadUserByTpsUuid(String uuid) {
        return loginUserModel;
    }

    @Override
    public LoginUserModel wrapLoginUserPerm(LoginUserModel loginUserModel) {
        loginUserModel.setRoleIdList(Collections.singletonList(1));
        loginUserModel.setRoleCodeList(Collections.singletonList("ROLE_ADMIN"));
        loginUserModel.setMenuIdList(Arrays.asList(1, 2, 3));
        loginUserModel.setMenuPermList(Arrays.asList("user:query", "user:add", "user:edit"));
        return loginUserModel;
    }

}
